﻿using Client;
using Shared.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StationClient.Dialog
{
    public partial class DialogLine : Form
    {
        STATION _sta = null;
        List<LINE> _listLine = null;

        public DialogLine(STATION  sta)
        {
            _sta = sta;
            InitializeComponent();
        }

        private void DialogLine_Load(object sender, EventArgs e)
        {
            //添加ListView表头
            //ColumnHeader head = new ColumnHeader();
            //head.Text = "ID";
            //head.Width = 120;
            //head.TextAlign = HorizontalAlignment.Left;
            //this.listViewLine.Columns.Add(head);
            //this.listViewLine.Columns.Add("产线编码", 120, HorizontalAlignment.Center);
            //this.listViewLine.Columns.Add("产线名称", 120, HorizontalAlignment.Center);
            //this.listViewLine.Columns.Add("流程编码", 120, HorizontalAlignment.Center);
            //this.listViewLine.Columns.Add("产线描述", 120, HorizontalAlignment.Center);
            //this.listViewLine.Columns.Add("组长员工号", 120, HorizontalAlignment.Center);
            //this.listViewLine.Columns.Add("组长姓名", 120, HorizontalAlignment.Center);

            this.listViewLine.BeginUpdate();

            LINE lineWhere = new LINE();
            var lineRes = MethodWcf.SelectLineClient(lineWhere);
            if (lineRes.result)
            {
                _listLine = lineRes.value;
                for (int i = 0; i < _listLine.Count; i++)
                {
                    LINE line = _listLine[i];

                    ListViewItem item = new ListViewItem();
                    item.Text = line.ID.ToString();
                    item.ImageIndex = 1;
                    item.SubItems.Add(line.NAME);
                    item.SubItems.Add(line.FLOW_ID.ToString());
                    item.SubItems.Add(line.CONTEXT);
                    item.SubItems.Add(line.LEADER_ID.ToString());
                    item.SubItems.Add(line.LEADER_NAME);
                    this.listViewLine.Items.Add(item);
                }
            }
            this.listViewLine.EndUpdate();
        }

        private void listViewLine_MouseClick(object sender, MouseEventArgs e)
        {
            var selected = this.listViewLine.SelectedItems;

            if (this._listLine.Count>=1&&selected.Count==1)//ITEM的数量大于1
            {
                //查到相应的Line信息
                long lineId = long.Parse(selected[0].Text);
                var line = (from l in _listLine
                            where l.ID == lineId
                            select l).FirstOrDefault();

                _sta.LINE_ID = line.ID;
                _sta.FLOW_ID = line.FLOW_ID;
            }

            this.Close();
        }
    }
}
